package com.fly.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fly.demo.model.UserInfo;
import com.fly.demo.service.UserInfoSevice;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
public class UserInfoController
{
    @Autowired
    private UserInfoSevice userInfoSevice;
    
    @GetMapping({"/", "index"})
    public String index(Model model)
    {
        UserInfo user = userInfoSevice.selectUserDetail();
        model.addAttribute("user", user);
        return "index";
    }
    
    @GetMapping({"about", "about.html"})
    public String about(ModelMap modelMap)
    {
        modelMap.put("name", "huanhuan");
        return "about";
    }
    
    @GetMapping({"new", "new.html"})
    public String newArticle()
    {
        return "new";
    }
    
    @GetMapping({"newlist", "newlist.html"})
    public String newArticleList()
    {
        return "newlist";
    }
    
    @GetMapping({"share", "share.html"})
    public String share()
    {
        return "share";
    }
    
    @ResponseBody
    @GetMapping(value = "test", produces = MediaType.APPLICATION_JSON_VALUE)
    public List<UserInfo> selectAll()
    {
        return userInfoSevice.selectAll();
    }
    
    @ResponseBody
    @GetMapping("logtest")
    public void logtest()
    {
        log.debug("------------debug test ");
        log.info("------------info test ");
        log.warn("------------warn test ");
        log.error("error test message", new Exception("Testing"));
    }
}
